//
//  APUnlockAlertViewController.m
//  AqualPolo
//
//  Created by dong on 2024/5/15.
//

#import "APUnlockAlertViewController.h"
#import "APHomeBallAlertView.h"
#import "APHomeDataManager.h"
@interface APUnlockAlertViewController ()
@property (nonatomic, strong) APHomeBallAlertView *mainView;

@end

@implementation APUnlockAlertViewController
- (APHomeBallAlertView *)mainView{
    if (!_mainView) {
        _mainView = [[APHomeBallAlertView alloc] init];
        [_mainView.clickButton addTarget:self action:@selector(clickButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _mainView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = LYRGBColor(10, 24, 69);
    [self.view addSubview:self.mainView];
    [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.view);
        make.left.equalTo(self.view).offset(30);
        make.right.equalTo(self.view).offset(-30);
    }];
    [self reloadData];
}


- (void)reloadData{
    [[APHomeDataManager shareInstance] unlockBall:_ballType];
    NSString *ballImageName = [BaseDataManager ballImageName:_ballType];
    self.mainView.ballImageView.image = [UIImage imageNamed:ballImageName];
    NSString *ballName = [BaseDataManager ballName:_ballType];
    self.mainView.ballNameLabel.text = [NSString stringWithFormat:@"【%@】",ballName];
    self.mainView.contentLabel.text = @"Congratulations on successfully unlocking the pendant and obtaining the title.";
    [self.mainView.clickButton setTitle:@"OK" forState:UIControlStateNormal];
    self.mainView.msgLabel.hidden = true;
}


- (void)clickButtonDidClick:(UIButton *)sender{
    [self dismissViewControllerAnimated:true completion:nil];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    }
    return self;
}

@end
